package cn.spring.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.spring.bean.Employee;
import cn.spring.dao.EmployeeMapper;
import cn.spring.service.EmplyoeeService;

@Service
@Transactional
public class EmpServiceImpl implements EmplyoeeService {

	@Resource
	private EmployeeMapper userDao;
	
	@Override
	public List<Employee> findAll() {
		// TODO Auto-generated method stub
		return userDao.getAll();
	}

	@Override
	public Employee login(Employee emp) {
		// TODO Auto-generated method stub
		Employee user=new Employee();
		try {
			user = userDao.login(emp);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		return user;
	}

	@Override
	public Employee save(Employee emp) {
		// TODO Auto-generated method stub
		int count=userDao.insert(emp);
		if(count>0){
			Employee user=userDao.selectByPrimaryKey(emp.getId());
			return user;
		}else{
			return null;
		}
	}

	@Override
	public int phonePan(String phone) {
		// TODO Auto-generated method stub
		return userDao.phonePan(phone);
	}

	@Override
	public int updateIstong(Integer id, Integer state) {
		// TODO Auto-generated method stub
		return userDao.updateIstong(id, state);
	}

	@Override
	public int updateRole(Integer id, Integer role) {
		// TODO Auto-generated method stub
		return userDao.updateRole(id, role);
	}

	@Override
	public List<Employee> findAllById(Integer id) {
		// TODO Auto-generated method stub
		return userDao.getAllById(id);
	}

	@Override
	public void xiugaidianming(String name,@Param("id")Integer id) {
		// TODO Auto-generated method stub
		userDao.xiugaidianming(name, id);
	}

	@Override
	public int updatePwd(String pwd, Integer id) {
		// TODO Auto-generated method stub
		return userDao.updatePwd(pwd, id);
	}

}
